package com.zzyl;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSONUtil;
import com.zzyl.service.WeChatService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
public class test {
    @Autowired
    WeChatService weChatService;
    @Test
    public void test(){
        System.out.println("xixi");
    }
    @Test
    public void testGet1(){
        String string = HttpUtil.get("https://www.baidu.com");
        System.out.println(string);
    }
    @Test
    public void testGet2(){
        String url="http://localhost:9995/nursing_project";
        HashMap<String,Object> map =new HashMap<>();
        map.put("pageNum",1);
        map.put("pageSize",10);
        String result=HttpUtil.get(url,map);
        System.out.println(result);
    }
    @Test
    public void testGet3(){
        String url="http://localhost:9995/nursing_project";
        HashMap<String,Object> map =new HashMap<>();
        map.put("pageNum",1);
        map.put("pageSize",10);
        HttpResponse result = HttpUtil.createRequest(Method.GET, url).form(map).execute();
        if (result.getStatus()==200){
            System.out.println(result.body());
        }
    }
    @Test
    public void testPost1(){
        String url="http://localhost:9995/nursing_project";
        HashMap<String,Object> map =new HashMap<>();
        map.put("name", "护理项目测试232");
        map.put("orderNo", 1);
        map.put("unit", "次");
        map.put("price", 10.00);
        map.put("image", "https://yjy-slwl-oss.oss-cn-hangzhou.aliyuncs.com/ae7cf766-fb7b-49ff-a73c-c86c25f280e1.png");
        map.put("nursingRequirement", "无特殊要求");
        map.put("status", 1);
        String result=HttpUtil.post(url, JSONUtil.toJsonStr(map));
        System.out.println(result);
    }
    @Test
    public void testPost2(){
        String url="http://localhost:9995/nursing_project";
        HashMap<String,Object> map =new HashMap<>();
        map.put("name", "护理项目测试2332");
        map.put("orderNo", 1);
        map.put("unit", "次");
        map.put("price", 10.00);
        map.put("image", "https://yjy-slwl-oss.oss-cn-hangzhou.aliyuncs.com/ae7cf766-fb7b-49ff-a73c-c86c25f280e1.png");
        map.put("nursingRequirement", "无特殊要求");
        map.put("status", 1);
        HttpResponse response = HttpUtil.createRequest(Method.POST, url)
                .body(JSONUtil.toJsonStr(map))
                .execute();
        if(response.getStatus() == 200){
            System.out.println(response.body());
        }
    }
    @Test
    public void testWeater() {
        String url = "https://aliv18.data.moji.com/whapi/json/alicityweather/forecast24hours";
        String appcode = "68e795b36bac44c7ae6525a8777f96d7";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("cityId", "1399");

        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        param.put("token", "008d2ad9197090c5dddc76f583616606");
        bodys.put("cityId", "2");

        HttpResponse response = HttpUtil.createRequest(Method.POST, url)
                .header("Authorization", "APPCODE " + appcode)
                .form(param)
                .execute();
        if (response.getStatus() == 200) {
            System.out.println(response.body());
        }

    }
    @Test
    public void NaWoWenNi(){
        System.out.println("那我问你");
        NaWoWenNi();
    }
    @Test
    public void testOpenId() throws IOException {
        String openId = weChatService.getOpenId("0c3L64ll2YH0le4v3Tnl2HjISv0L64lD");
        System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        System.out.println(openId);
    }
    @Test
    public void testGetPhone() throws IOException {
        String phone = weChatService.getPhone("1c2f0d9baa3504f3d6bd362f761bde872b700ccc08da7876ef8856a36b099f54");
        System.out.println(phone);
    }
}
